package com.sls.game.supply.deal;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import com.sls.core.http.HttpClient;
import com.sls.core.socket.Head;
import com.sls.core.util.UtilMD5Encryption;
import com.sls.game.common.DeductionRefund;
import com.sls.game.dao.DownstreamUserDAO;
import com.sls.game.dao.GoodsInfoManageDAO;
import com.sls.game.dao.GoodsOrderDAO;
import com.sls.game.dao.GoodsOrderLogDAO;
import com.sls.game.dao.SpecialPriceSystemDAO;
import com.sls.game.dao.nutsnet.ChargeTypeInfoDAO;
import com.sls.game.dao.xingxitian.XingAccountTypeDAO;
import com.sls.game.dao.xingxitian.XingChargeTypeDAO;
import com.sls.game.dao.xingxitian.XingGameAreaSrvDAO;
import com.sls.game.dao.xingxitian.XingParvalueDAO;
import com.sls.game.parser.xingqitian.ParseTradeResMsg;
import com.sls.game.parser.xingqitian.XingConfigRead;
import com.sls.game.pojo.DeductionRefundInfo;
import com.sls.game.pojo.GoodsOrderInfo;
import com.sls.game.pojo.SLSHttpInterfaceInfo;
import com.sls.game.pojo.xingqitian.XingAccountTypeInfo;
import com.sls.game.pojo.xingqitian.XingChargeTypeInfo;
import com.sls.game.pojo.xingqitian.XingConfigInfo;
import com.sls.game.pojo.xingqitian.XingGameAreaSrvInfo;
import com.sls.game.pojo.xingqitian.XingParvalueInfo;
import com.sls.game.pojo.xingqitian.XingTradeResMsgInfo;

/**
 * 
 * @description 星启天交易处理
 * @author Wangxuegang
 * @date 2012-12-22
 */
public class XingQiTianTradeOfDeal {

	private static Logger log = Logger.getLogger(XingQiTianTradeOfDeal.class);

	/**
	 * 星启天充值返回结果处理
	 * 
	 * @param info
	 * @param originalGoodsId
	 * @param orderId
	 * @param head
	 * @param orderTime
	 * @param paymentOrderNo
	 * @return
	 */
	public static SLSHttpInterfaceInfo dealTradeResultOfXingQiTian(
			SLSHttpInterfaceInfo info, String originalGoodsId, String orderId,
			Head head, String orderTime, String paymentOrderNo,
			XingParvalueDAO xingParvalueDAO,
			XingChargeTypeDAO xingChargeTypeDAO,
			XingAccountTypeDAO xingAccountTypeDAO,
			XingGameAreaSrvDAO xingGameAreaSrvDAO,
			ChargeTypeInfoDAO chargeTypeInfoDAO, GoodsOrderDAO goodsOrderDAO,
			DownstreamUserDAO downstreamUserDAO,
			GoodsOrderLogDAO goodsOrderLogDAO,
			GoodsInfoManageDAO goodsInfoManageDAO,
			SpecialPriceSystemDAO specialPriceSystemDAO) {

		XingConfigInfo xingConfigInfo = new XingConfigInfo();
		xingConfigInfo = XingConfigRead.readConfig();
		String merchantid = xingConfigInfo.getUserNo().trim(); // 商户ID
		GoodsOrderInfo orderInfo = new GoodsOrderInfo();
		orderInfo.setRegisterAccount(merchantid);
		updateGoodsOrder(orderId, head, orderInfo, goodsOrderDAO);

		XingTradeResMsgInfo resMsgInfo = tradeOfXingQiTian(info,
				originalGoodsId, orderId, head, orderTime, xingParvalueDAO,
				xingChargeTypeDAO, xingAccountTypeDAO, xingGameAreaSrvDAO);

		// 返回给上层对象
		SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
		if (resMsgInfo != null) {
			// 响应码
			String resultnoValue = resMsgInfo.getResultnoValue();
			String retmsg = resMsgInfo.getRetmsgValue();
			if ("0000".equals(resultnoValue)) { // 订单提交成功
				sLSHttpInterfaceInfo.setResMsg("SUCCESS");
				sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
				sLSHttpInterfaceInfo.setStatus("ORDER_UNDERWAY");
				sLSHttpInterfaceInfo.setSupOrderNo(orderId);
			} else { // 订单提交失败
				sLSHttpInterfaceInfo.setResMsg("FAILED");
				sLSHttpInterfaceInfo.setFailedCode("208");
				sLSHttpInterfaceInfo.setFailedReason("充值失败");
				sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
				sLSHttpInterfaceInfo.setStatus("ORDER_FAILED");
				sLSHttpInterfaceInfo.setSupOrderNo(orderId);

				// 更新订单
				GoodsOrderInfo goodsOrderInfo1 = new GoodsOrderInfo();
				DeductionRefundInfo dedInfo = null;
				String paymentStatus = "";
				// 退款
				dedInfo = DeductionRefund.invokeDeductRefund(info, orderId,
						"1", orderTime, paymentOrderNo, head, goodsOrderDAO);
				if (dedInfo != null) {
					paymentStatus = dedInfo.getPaymentStatus();
				}
				if ("1".equals(paymentStatus)) { // 成功
					goodsOrderInfo1.setIsPay("3"); // 退款成功
					// 退款成功，通知下游用户
					DeductionRefund.noticeUserRefundMsg(orderId, dedInfo,
							goodsOrderDAO, downstreamUserDAO, goodsOrderLogDAO);

				} else if ("2".equals(paymentStatus)) {
					goodsOrderInfo1.setIsPay("2"); // 退款失败
				}
				goodsOrderInfo1.setStatus("0");
				goodsOrderInfo1.setStatusRemark(retmsg);
				try {
					updateGoodsOrder(orderId, head, goodsOrderInfo1,
							goodsOrderDAO);
				} catch (Exception e) {
					log.error("请求ID：" + head.getRequestId() + "根据退款状态更新订单异常！",
							e);
				}
			}
		} else {
			GoodsOrderInfo or = new GoodsOrderInfo();
			or.setStatus("3");
			updateGoodsOrder(orderId, head, or, goodsOrderDAO);
			sLSHttpInterfaceInfo.setResMsg("SUCCESS");
			sLSHttpInterfaceInfo.setFailedCode("210");
			sLSHttpInterfaceInfo.setFailedReason("订单存疑");
			sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
			sLSHttpInterfaceInfo.setStatus("ORDER_DUBIOUS");
			sLSHttpInterfaceInfo.setSupOrderNo(orderId);
		}

		return sLSHttpInterfaceInfo;
	}

	/**
	 * 根据交易返回的结果更新订单表
	 * 
	 * @param orderId
	 * @param head
	 * @param info
	 */
	private static void updateGoodsOrder(String orderId, Head head,
			GoodsOrderInfo info, GoodsOrderDAO goodsOrderDAO) {
		info.setOrderId(orderId);
		info.setSynOrAsy("0"); // 同步返回通知标识
		// 数据更新
		try {
			goodsOrderDAO.update(info);
		} catch (Exception e) {
			log.error("Service处理[" + head.getRequestId() + "]的请求出现异常！", e);
		}

	}

	/**
	 * 星启天交易
	 * 
	 * @param info
	 * @param originalGoodsId
	 * @param orderId
	 * @param head
	 * @param orderTime
	 * @return
	 */
	private static XingTradeResMsgInfo tradeOfXingQiTian(
			SLSHttpInterfaceInfo info, String originalGoodsId, String orderId,
			Head head, String orderTime, XingParvalueDAO xingParvalueDAO,
			XingChargeTypeDAO xingChargeTypeDAO,
			XingAccountTypeDAO xingAccountTypeDAO,
			XingGameAreaSrvDAO xingGameAreaSrvDAO) {

		HttpClient httpClient = new HttpClient();
		String url = obtainOfXingTrade(info, originalGoodsId, orderId,
				orderTime, xingParvalueDAO, xingChargeTypeDAO,
				xingAccountTypeDAO, xingGameAreaSrvDAO);

		String supplyEncode = "GB2312";
		try {
			log.info("请求ID：" + head.getRequestId() + "，发送到星启天的直充请求参数为：" + url);
			String xmlStr = httpClient.doGet(url, supplyEncode);
			log.info("请求ID：" + head.getRequestId() + "，星启天直充返回的结果参数为：" + xmlStr);
			if (xmlStr != null && !("".equals(xmlStr))) {
				XingTradeResMsgInfo resMsg = ParseTradeResMsg
						.parseMsgOfTrade(xmlStr);
				return resMsg;
			}
		} catch (Exception e) {
			log.error("请求ID：" + head.getRequestId() + "星启天直充交易请求异常！", e);
		}

		return null;
	}

	/**
	 * 星启天发送订单参数列表
	 * 
	 * @param info
	 * @param originalGoodsId
	 * @param orderId
	 * @param orderTime
	 * @param xingParvalueDAO
	 * @param xingChargeTypeDAO
	 * @param xingAccountTypeDAO
	 * @param xingGameAreaSrvDAO
	 * @return
	 */
	private static String obtainOfXingTrade(SLSHttpInterfaceInfo info,
			String originalGoodsId, String orderId, String orderTime,
			XingParvalueDAO xingParvalueDAO,
			XingChargeTypeDAO xingChargeTypeDAO,
			XingAccountTypeDAO xingAccountTypeDAO,
			XingGameAreaSrvDAO xingGameAreaSrvDAO) {
		XingConfigInfo xingConfigInfo = new XingConfigInfo();
		xingConfigInfo = XingConfigRead.readConfig();
		String merchantid = xingConfigInfo.getUserNo().trim(); // 商户ID
		String tradeAddress = xingConfigInfo.getTradeAddress().trim(); // 交易地址
		String merchantkey = xingConfigInfo.getUserKey().trim(); // 密钥
		String productid = ""; // 商品类型ID
		String parvalueName = ""; // 商品面值名称
		String parvalueId = ""; // 商品面值

		// 赠品名称
		String choosegemName = "";
		// 赠品名称Id
		String choosegemId = "";

		String buynumber = info.getBuyNum();

		String tranid = orderId; // 手拉手订单号
		String playerusername = info.getGameAccount(); // 充值账号
		String remoteIp = info.getClientIp(); // 玩家充值IP
		String chargetypeName = info.getChargeTypeName();
		String chargeTypeId = "";
		String gametype1 = "";
		String gametype = "";
		String salePrice = "";
		String tbuyNumberStr = "";
		String buyNumberList = "";
		String tbuynumbername = "";

		// 根据原始商品编号，查询面额信息表
		XingParvalueInfo xingParvalueInfo = null;
		xingParvalueInfo = xingParvalueDAO
				.queryParvalueInfoByGoodsId(originalGoodsId);
		if (xingParvalueInfo != null) {
			productid = xingParvalueInfo.getProductid();
			parvalueName = xingParvalueInfo.getParvalueName();
			parvalueId = xingParvalueInfo.getParvalueId();
			chargetypeName = xingParvalueInfo.getChargetypeName();
			chargeTypeId = xingParvalueInfo.getChargetypeId();
			gametype1 = xingParvalueInfo.getGametype1();
			gametype = xingParvalueInfo.getGametype();
			choosegemName = xingParvalueInfo.getChoosegemName();
			choosegemId = xingParvalueInfo.getChoosegemId();
			salePrice = xingParvalueInfo.getSaleprice();
			tbuyNumberStr = xingParvalueInfo.getTbuynumber_list();
			buyNumberList = xingParvalueInfo.getBuynumber_list();
			tbuynumbername = xingParvalueInfo.getTbuynumbername();
		}

		if (StringUtils.isEmpty(chargetypeName)) {
			XingChargeTypeInfo chargeTypeInfo = new XingChargeTypeInfo();
			chargetypeName = info.getChargeTypeName();
			chargeTypeInfo.setGametype1(gametype1);
			chargeTypeInfo.setChargetypeName(chargetypeName);
			XingChargeTypeInfo chargeType = xingChargeTypeDAO
					.queryChargeType(chargeTypeInfo);
			chargeTypeId = chargeType.getChargetypeId();
			tbuyNumberStr = chargeType.getTbuynumber_list();
			buyNumberList = chargeType.getBuynumber_list();
			tbuynumbername = chargeType.getTbuynumbername();
		}

		String accounttypeName = info.getAccountTypeName();
		XingAccountTypeInfo accountTypeInfo = new XingAccountTypeInfo();
		accountTypeInfo.setGametype1(gametype1);
		accountTypeInfo.setAccounttypeName(accounttypeName);
		String accounttypeId = null;
		accounttypeId = xingAccountTypeDAO.queryAccounttypeId(accountTypeInfo);

		String areaId = null;
		String srvId = null;
		String areaName = info.getGameArea();
		String srvName = info.getGameServer();

		XingGameAreaSrvInfo areaSrvInfo = new XingGameAreaSrvInfo();
		areaSrvInfo.setGametype1(gametype1);
		areaSrvInfo.setAreaName(areaName);
		areaSrvInfo.setSrvName(srvName);
		XingGameAreaSrvInfo areaSrvInfo1 = null;
		areaSrvInfo1 = xingGameAreaSrvDAO.queryAreaAndSrv(areaSrvInfo);
		if (areaSrvInfo1 != null) {
			areaId = areaSrvInfo1.getAreaId();
			srvId = areaSrvInfo1.getSrvId();
		}
		int index = 0;
		if (StringUtils.isNotEmpty(buyNumberList)) {
			String[] buyNumbers = buyNumberList.split(",");
			for (String b : buyNumbers) {
				if (buynumber.equals(b)) {
					break;
				} else {
					index++;
				}
			}

		}
		// 对应的转换点数
		String tbuynumber = "";
		if (StringUtils.isNotEmpty(tbuyNumberStr)) {
			String[] tbuyNumbers = tbuyNumberStr.split(",");
			tbuynumber = tbuyNumbers[index];
		}

		String url = createUrl(tradeAddress, merchantid, productid, buynumber,
				parvalueId, tranid, playerusername, srvId, parvalueName,
				chargetypeName, chargeTypeId, accounttypeName, accounttypeId,
				tbuynumber, areaName, areaId, srvName, merchantkey, remoteIp,
				choosegemName, choosegemId, salePrice, gametype, tbuynumbername);

		return url;
	}

	/**
	 * 拼接下订单url
	 * 
	 * @param tradeAddress
	 * @param merchantid
	 * @param productid
	 * @param buynumber
	 * @param parvalue1
	 * @param tranid
	 * @param playerusername
	 * @param srvId
	 * @param parvalue
	 * @param chargetypeName
	 * @param chargeTypeId
	 * @param accounttypeName
	 * @param accounttypeId
	 * @param tbuynumber
	 * @param areaName
	 * @param areaId
	 * @param srvName
	 * @param merchantkey
	 * @param remoteIp
	 * @param salePrice
	 * @param tbuynumbername
	 * @param gametype
	 * @return
	 */
	private static String createUrl(String tradeAddress, String merchantid,
			String productid, String buynumber, String parvalue1,
			String tranid, String playerusername, String srvId,
			String parvalue, String chargetypeName, String chargeTypeId,
			String accounttypeName, String accounttypeId, String tbuynumber,
			String areaName, String areaId, String srvName, String merchantkey,
			String remoteIp, String choosegemName, String choosegemId,
			String salePrice, String gametype, String tbuynumbername) {

		StringBuilder strBui = new StringBuilder();
		strBui.append(tradeAddress);
		strBui.append("?");
		strBui.append("merchantid=");
		strBui.append(merchantid);
		strBui.append("&");
		strBui.append("productid=");
		strBui.append(productid);
		strBui.append("&");
		strBui.append("buynumber=");
		strBui.append(buynumber);
		strBui.append("&");
		strBui.append("parvalue1=");
		strBui.append(parvalue1);
		strBui.append("&");
		strBui.append("tranid=");
		strBui.append(tranid);
		strBui.append("&");
		strBui.append("playerusername=");
		strBui.append(playerusername);
		strBui.append("&");

		if (srvId != null && !("".equals(srvId))) {
			strBui.append("gamesrv1=");
			try {
				srvId = URLEncoder.encode(srvId, "GB2312");
			} catch (UnsupportedEncodingException e) {
				log.error(e);
			}
			strBui.append(srvId);
			strBui.append("&");
		}
		strBui.append("parvalue=");
		try {
			parvalue = URLEncoder.encode(parvalue, "GB2312");
		} catch (UnsupportedEncodingException e) {
			log.error(e);
		}
		strBui.append(parvalue);
		strBui.append("&");
		if (chargetypeName != null && !("".equals(chargetypeName))) {
			strBui.append("chargetype=");
			try {
				chargetypeName = URLEncoder.encode(chargetypeName, "GB2312");
			} catch (UnsupportedEncodingException e) {
				log.error(e);
			}
			strBui.append(chargetypeName);
			strBui.append("&");
		}
		if (chargeTypeId != null && !("".equals(chargeTypeId))) {
			strBui.append("chargetype1=");
			try {
				chargeTypeId = URLEncoder.encode(chargeTypeId, "GB2312");
			} catch (UnsupportedEncodingException e) {
				log.error(e);
			}
			strBui.append(chargeTypeId);
			strBui.append("&");
		}
		if (accounttypeName != null && !("".equals(accounttypeName))) {
			strBui.append("accounttype=");
			try {
				accounttypeName = URLEncoder.encode(accounttypeName, "GB2312");
			} catch (UnsupportedEncodingException e) {
				log.error(e);
			}
			strBui.append(accounttypeName);
			strBui.append("&");
		}
		if (accounttypeId != null && !("".equals(accounttypeId))) {
			strBui.append("accounttype1=");
			try {
				accounttypeId = URLEncoder.encode(accounttypeId, "GB2312");
			} catch (UnsupportedEncodingException e) {
				log.error(e);
			}
			strBui.append(accounttypeId);
			strBui.append("&");
		}
		if (tbuynumber != null && !("".equals(tbuynumber))) {
			strBui.append("tbuynumber=");
			try {
				tbuynumber = URLEncoder.encode(tbuynumber, "GB2312");
			} catch (UnsupportedEncodingException e) {
				log.error(e);
			}
			strBui.append(tbuynumber);
			strBui.append("&");
		}
		if (areaName != null && !("".equals(areaName))) {
			strBui.append("gamearea=");
			try {
				areaName = URLEncoder.encode(areaName, "GB2312");
			} catch (UnsupportedEncodingException e) {
				log.error(e);
			}
			strBui.append(areaName);
			strBui.append("&");
		}
		if (areaId != null && !("".equals(areaId))) {
			strBui.append("gamearea1=");
			try {
				areaId = URLEncoder.encode(areaId, "GB2312");
			} catch (UnsupportedEncodingException e) {
				log.error(e);
			}
			strBui.append(areaId);
			strBui.append("&");
		}
		if (srvName != null && !("".equals(srvName))) {
			strBui.append("gamesrv=");
			try {
				srvName = URLEncoder.encode(srvName, "GB2312");
			} catch (UnsupportedEncodingException e) {
				log.error(e);
			}
			strBui.append(srvName);
			strBui.append("&");
		}

		// 赠品名称
		if (choosegemName != null && !("".equals(choosegemName))) {
			strBui.append("choosegem=");
			try {
				choosegemName = URLEncoder.encode(choosegemName, "GB2312");
			} catch (UnsupportedEncodingException e) {
				log.error(e);
			}
			strBui.append(choosegemName);
			strBui.append("&");
		}

		// 赠品名称Id
		if (choosegemId != null && !("".equals(choosegemId))) {
			strBui.append("choosegem1=");
			try {
				choosegemId = URLEncoder.encode(choosegemId, "GB2312");
			} catch (UnsupportedEncodingException e) {
				log.error(e);
			}
			strBui.append(choosegemId);
			strBui.append("&");
		}
		if (StringUtils.isNotEmpty(salePrice)) {
			strBui.append("saleprice=");
			strBui.append(salePrice);
			strBui.append("&");
		}
		if (StringUtils.isNotEmpty(gametype)) {
			strBui.append("gametype=");
			try {
				gametype = URLEncoder.encode(gametype, "GB2312");
			} catch (UnsupportedEncodingException e) {
				log.error(e);
			}
			strBui.append(gametype);
			strBui.append("&");
		}
		if (StringUtils.isNotEmpty(tbuynumbername)) {
			strBui.append("tbuynumbername=");
			try {
				tbuynumbername = URLEncoder.encode(tbuynumbername, "GB2312");
			} catch (UnsupportedEncodingException e) {
				log.error(e);
			}
			strBui.append(tbuynumbername);
			strBui.append("&");
		}

		strBui.append("replayerusername=");
		strBui.append(playerusername);
		strBui.append("&");
		strBui.append("RemoteIp=");
		strBui.append(remoteIp);
		strBui.append("&");

		String sign = createSignOfTrade(merchantid, productid, playerusername,
				buynumber, tranid, merchantkey);
		strBui.append("sign=");
		strBui.append(sign);

		String url = strBui.toString().trim();
		return url;
	}

	/**
	 * 下订单MD5签名
	 * 
	 * @param merchantid
	 * @param productid
	 * @param playerusername
	 * @param buynumber
	 * @param tranid
	 * @param merchantkey
	 * @return
	 */
	public static String createSignOfTrade(String merchantid, String productid,
			String playerusername, String buynumber, String tranid,
			String merchantkey) {
		StringBuilder strBui = new StringBuilder();
		strBui.append("merchantid=");
		strBui.append(merchantid);
		strBui.append("&");
		strBui.append("productid=");
		strBui.append(productid);
		strBui.append("&");
		strBui.append("playerusername=");
		strBui.append(playerusername);
		strBui.append("&");
		strBui.append("buynumber=");
		strBui.append(buynumber);
		strBui.append("&");
		strBui.append("tranid=");
		strBui.append(tranid);
		strBui.append("&");
		strBui.append("merchantkey=");
		strBui.append(merchantkey);

		String data = strBui.toString().trim();
		String sign = UtilMD5Encryption.createMD5EncryptionForCapital(data);

		return sign;
	}

	/**
	 * 订单结果查询MD5签名
	 * 
	 * @param merchantid
	 * @param tranid
	 * @param playerusername
	 * @param merchantkey
	 * @return
	 */
	public static String createSignOfOrderQuery(String merchantid,
			String tranid, String playerusername, String merchantkey) {
		StringBuilder strBui = new StringBuilder();
		strBui.append("merchantid=");
		strBui.append(merchantid);
		strBui.append("&");
		strBui.append("tranid=");
		strBui.append(tranid);
		strBui.append("&");
		strBui.append("playerusername=");
		strBui.append(playerusername);
		strBui.append("&");
		strBui.append("merchantkey=");
		strBui.append(merchantkey);
		String data = strBui.toString().trim();
		String sign = UtilMD5Encryption.createMD5EncryptionForCapital(data);

		return sign;
	}

	/**
	 * 商品详细
	 * 
	 * @param sLSHttpInterfaceInfo
	 * @param originalGoodsId
	 * @param xingParvalueDAO
	 * @param xingAccountTypeDAO
	 * @param xingChargeTypeDAO
	 * @param xingGameAreaSrvDAO
	 * @return
	 */
	public static SLSHttpInterfaceInfo getGoodsDetailOfXing(
			SLSHttpInterfaceInfo sLSHttpInterfaceInfo, String originalGoodsId,
			XingParvalueDAO xingParvalueDAO,
			XingAccountTypeDAO xingAccountTypeDAO,
			XingChargeTypeDAO xingChargeTypeDAO,
			XingGameAreaSrvDAO xingGameAreaSrvDAO) {
		String gametype1 = null;
		XingParvalueInfo parvalueInfo = null;
		parvalueInfo = xingParvalueDAO
				.queryParvalueInfoByGoodsId(originalGoodsId);
		if (parvalueInfo != null) {
			gametype1 = parvalueInfo.getGametype1();

			List<XingParvalueInfo> chargeTypeList = null;
			chargeTypeList = xingParvalueDAO
					.queryChargeTypeByGoodsId(originalGoodsId);
			if (chargeTypeList != null && chargeTypeList.size() > 0) {
				StringBuilder strBui = new StringBuilder();
				for (XingParvalueInfo info : chargeTypeList) {
					String chargetypeName = info.getChargetypeName();
					if (chargetypeName != null && !("".equals(chargetypeName))) {
						strBui.append(chargetypeName);
						strBui.append("##");
					} else {
						strBui.append("null");
						strBui.append("##");
					}

					String buynumber_list = info.getBuynumber_list();
					if (buynumber_list != null && !("".equals(buynumber_list))) {
						strBui.append(buynumber_list);
						strBui.append("##");
					} else {
						strBui.append("1"); // 默认是1个
						strBui.append("##");
					}

					String tbuynumber_list = info.getTbuynumber_list();
					if (tbuynumber_list != null
							&& !("".equals(tbuynumber_list))) {
						strBui.append(tbuynumber_list);
						strBui.append("##");
					} else {
						strBui.append("null");
						strBui.append("##");
					}

					String tbuynumbername = info.getTbuynumbername();
					if (tbuynumbername != null && !("".equals(tbuynumbername))) {
						strBui.append(tbuynumbername);
					} else {
						strBui.append("null");
					}
					strBui.append("&&");
				}
				String value = strBui.toString().trim();
				String chargeType = value.substring(0, value.length() - 2);
				sLSHttpInterfaceInfo.setChargeType(chargeType);
			}
		}

		List<XingAccountTypeInfo> accountList = null;
		accountList = xingAccountTypeDAO.queryRecordInfoByGametype1(gametype1);
		if (accountList != null && accountList.size() > 0) {
			StringBuilder strBui = new StringBuilder();
			for (XingAccountTypeInfo info : accountList) {
				String accounttypeName = info.getAccounttypeName();
				if (accounttypeName != null && !("".equals(accounttypeName))) {
					strBui.append(accounttypeName);
				}
				strBui.append("&&");
			}
			String value = strBui.toString().trim();
			String accounttypeName = value.substring(0, value.length() - 2);
			sLSHttpInterfaceInfo.setAccountType(accounttypeName);
		}

		List<XingChargeTypeInfo> chargeTypeList = null;
		chargeTypeList = xingChargeTypeDAO
				.queryChargeTypeBygametype1(gametype1);
		if (chargeTypeList != null && chargeTypeList.size() > 0) {
			StringBuilder strBui = new StringBuilder();
			for (XingChargeTypeInfo info : chargeTypeList) {
				String chargetypeName = info.getChargetypeName();
				if (chargetypeName != null && !("".equals(chargetypeName))) {
					strBui.append(chargetypeName);
					strBui.append("##");
				} else {
					strBui.append("null");
					strBui.append("##");
				}

				String buynumber_list = info.getBuynumber_list();
				if (buynumber_list != null && !("".equals(buynumber_list))) {
					strBui.append(buynumber_list);
					strBui.append("##");
				} else {
					strBui.append("1"); // 默认是1个
					strBui.append("##");
				}

				String tbuynumber_list = info.getTbuynumber_list();
				if (tbuynumber_list != null && !("".equals(tbuynumber_list))) {
					strBui.append(tbuynumber_list);
					strBui.append("##");
				} else {
					strBui.append("null");
					strBui.append("##");
				}

				String tbuynumbername = info.getTbuynumbername();
				if (tbuynumbername != null && !("".equals(tbuynumbername))) {
					strBui.append(tbuynumbername);
				} else {
					strBui.append("null");
				}
				strBui.append("&&");
			}
			String value = strBui.toString().trim();
			String chargeType = value.substring(0, value.length() - 2);
			sLSHttpInterfaceInfo.setChargeType(chargeType);
		}

		List<XingGameAreaSrvInfo> areaList = null;
		String gameAreaName = null;
		areaList = xingGameAreaSrvDAO.queryGameAreaBygametype1(gametype1);
		if (areaList != null && areaList.size() > 0) {
			StringBuilder strBui = new StringBuilder();
			for (XingGameAreaSrvInfo info : areaList) {
				String areaName = info.getAreaName();
				if (areaName != null && !("".equals(areaName))) {
					strBui.append(areaName);
				}
				strBui.append("&&");
			}
			String value = strBui.toString().trim();
			gameAreaName = value.substring(0, value.length() - 2);
			sLSHttpInterfaceInfo.setGameArea(gameAreaName);
		}

		if (gameAreaName != null && gameAreaName.length() > 0) {
			String[] areaArr = gameAreaName.split("&&");
			for (int i = 0; i < areaArr.length; i++) {
				String areaName = areaArr[i];
				XingGameAreaSrvInfo srvInfo = new XingGameAreaSrvInfo();
				srvInfo.setAreaName(areaName);
				srvInfo.setGametype1(gametype1);

				List<XingGameAreaSrvInfo> srvList = null;
				srvList = xingGameAreaSrvDAO.queryGameSrvBygametype1(srvInfo);
				if (srvList != null && srvList.size() > 0) {
					StringBuilder strBui = new StringBuilder();
					for (XingGameAreaSrvInfo info : srvList) {
						if (areaName != null && !("".equals(areaName))) {
							strBui.append(areaName);
							strBui.append("##");
						} else {
							strBui.append("null");
							strBui.append("##");
						}

						String srvName = info.getSrvName();
						if (srvName != null && !("".equals(srvName))) {
							strBui.append(srvName);
						} else {
							strBui.append("null");
						}
						strBui.append("&&");
					}
					String value = strBui.toString().trim();
					String gameServerName = value.substring(0,
							value.length() - 2);
					sLSHttpInterfaceInfo.setGameServer(gameServerName);
				}
			}
		}

		sLSHttpInterfaceInfo.setGameUnit("张");
		return sLSHttpInterfaceInfo;
	}

}
